home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Embed / Sources / EmbedFra.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.6 KB  |  255 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                EmbedFra.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. #ifndef EMBEDFRAME_H
  15. #include "EmbedFra.h"
  16. #endif
  17.  
  18. #ifndef EMBEDPART_H
  19. #include "EmbedPar.h"
  20. #endif
  21.  
  22. #ifndef EMBEDPROXY_H
  23. #include "EmbedPxy.h"
  24. #endif
  25.  
  26. #ifndef EMBEDCMD_H
  27. #include "EmbedCmd.h"
  28. #endif
  29.  
  30. // ----- Framework Includes -----
  31.  
  32. #ifndef FWUTIL_H
  33. #include "FWUtil.h"
  34. #endif
  35.  
  36. #ifndef FWPRESEN_H
  37. #include "FWPresen.h"
  38. #endif
  39.  
  40. #ifndef FWPXYFRM_H
  41. #include "FWPxyFrm.h"
  42. #endif
  43.  
  44. // ----- OS Layer Includes -----
  45.  
  46. #ifndef FWODGEOM_H
  47. #include "FWODGeom.h"
  48. #endif
  49.  
  50. #ifndef FWRECSHP_H
  51. #include "FWRecShp.h"
  52. #endif
  53.  
  54. #ifndef FWMNUBAR_H
  55. #include "FWMnuBar.h"
  56. #endif
  57.  
  58. // ----- OpenDoc Includes -----
  59.  
  60. #ifndef SOM_Module_OpenDoc_Commands_defined
  61. #include <CmdDefs.xh>
  62. #endif
  63.  
  64. #ifndef SOM_Module_OpenDoc_StdProps_defined
  65. #include <StdProps.xh>
  66. #endif
  67.  
  68. //========================================================================================
  69. //    Runtime information
  70. //========================================================================================
  71.  
  72. #ifdef FW_BUILD_MAC
  73. #pragma segment odfembed
  74. #endif
  75.  
  76. //========================================================================================
  77. //    CLASS CEmbedFrame
  78. //========================================================================================
  79.  
  80. //----------------------------------------------------------------------------------------
  81. //     CEmbedFrame::CEmbedFrame
  82. //----------------------------------------------------------------------------------------
  83.  
  84. CEmbedFrame::CEmbedFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CEmbedPart* part) :
  85.     FW_CEmbeddingFrame(ev, odFrame, presentation, part),
  86.     fPart(part)
  87. {
  88.     SetDroppable(ev, TRUE);
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //     CEmbedFrame::~CEmbedFrame
  93. //----------------------------------------------------------------------------------------
  94.  
  95. CEmbedFrame::~CEmbedFrame()
  96. {
  97. }
  98.  
  99. //----------------------------------------------------------------------------------------
  100. //     CEmbedFrame::Draw
  101. //----------------------------------------------------------------------------------------
  102.  
  103. void CEmbedFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  104. {
  105.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  106.  
  107.     FW_CRectShape::RenderRect(vc, GetBounds(ev), FW_kFill, FW_kRGBBlue);
  108. }
  109.  
  110. //---------------------------------------------------------------------------------------
  111. //    CEmbedFrame::DoAdjustMenus
  112. //---------------------------------------------------------------------------------------
  113.  
  114. FW_Boolean CEmbedFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  115. {
  116.     if (hasMenuFocus)
  117.     {
  118.         // Check clipboard for a part to paste
  119.         menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContentFrame, NULL));
  120.     
  121.         // If an embedded part is selected, change Copy menu item to "Copy Part"
  122.         if (GetPresentation(ev)->GetSelection(ev)->IsEmpty(ev))
  123.             menuBar->SetItemString(ev, kODCommandCopy, FW_CString32("Copy"));
  124.         else
  125.             menuBar->SetItemString(ev, kODCommandCopy, FW_CString32("Copy Part"));
  126.     }
  127.     
  128.     return FALSE;
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    CEmbedFrame::EmbedSingleFrame
  133. //----------------------------------------------------------------------------------------
  134.  
  135. void CEmbedFrame::EmbedSingleFrame(Environment* ev,
  136.                                    ODPart* odEmbeddedPart, 
  137.                                    ODFrame* odEmbeddedFrame,
  138.                                    ODShape* suggestedFrameShape)
  139. {
  140. FW_UNUSED(suggestedFrameShape);
  141.  
  142.     // ----- Remove existing embedded part -----
  143.     GetPresentation(ev)->GetSelection(ev)->ClearSelection(ev);
  144.  
  145.     // ----- Calculate the frame shape -----
  146.     FW_CAcquiredODShape aqFrameShape = MakeFrameShape(ev);
  147.         
  148.     // ----- Create the proxy -----
  149.     CEmbedProxy* newProxy = new CEmbedProxy(ev, fPart);
  150.     
  151.     // ----- Embed the Part/Frame -----
  152.     GetPresentation(ev)->Embed(ev, 
  153.                              odEmbeddedPart, 
  154.                              odEmbeddedFrame,
  155.                              newProxy, 
  156.                              aqFrameShape, 
  157.                              FW_CPart::gViewAsFrameToken, 
  158.                              NULL,        // no presentation
  159.                                0,            // group id
  160.                                FALSE);    // sub-frame?
  161.  
  162.     // ----- Set the proxy  -----
  163.     fPart->SetProxy(ev, newProxy);
  164.  
  165.     // ----- Make sure frame gets redrawn ----
  166.     GetPresentation(ev)->Invalidate(ev);
  167. }
  168.  
  169. //----------------------------------------------------------------------------------------
  170. //    CEmbedFrame::MakeFrameShape
  171. //----------------------------------------------------------------------------------------
  172. //    Returns a new shape equals to my frame shape inset by eight pixels. Otherwise I can't drop 
  173. //    anything
  174.  
  175. ODShape* CEmbedFrame::MakeFrameShape(Environment* ev)
  176. {
  177.     FW_CRect bounds = GetBounds(ev);
  178.     bounds.Inset(FW_IntToFixed(8), FW_IntToFixed(8));
  179.     bounds.Place(FW_kFixed0, FW_kFixed0);        // Frame shape always zero based
  180.     return ::FW_NewODShape(ev, bounds);
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    CEmbedFrame::CreateEmbeddedFacet
  185. //----------------------------------------------------------------------------------------
  186.  
  187. ODFacet* CEmbedFrame::CreateEmbeddedFacet(Environment* ev,
  188.                                         ODFacet* embeddingFacet,
  189.                                         FW_MProxy* proxy,
  190.                                         ODFrame* embeddedFrame,
  191.                                         ODShape* proposedClipShape)
  192. {
  193.     FW_CAcquiredODTransform aqExternalTransform = ::FW_NewODTransform(ev, FW_CPoint(FW_IntToFixed(8), FW_IntToFixed(8)));
  194.  
  195.     return embeddingFacet->CreateEmbeddedFacet(ev,
  196.                                                 embeddedFrame,
  197.                                                 proposedClipShape,
  198.                                                 aqExternalTransform,
  199.                                                 NULL,                    // Canvas
  200.                                                 NULL,                    // biasCanvas
  201.                                                 NULL,                    // siblingFacet
  202.                                                 kODFrameInFront);
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. //    CEmbedFrame::FrameShapeChanged
  207. //----------------------------------------------------------------------------------------
  208. //    Change the frame shape of the embedded frame to be the same as mine
  209.  
  210. void CEmbedFrame::FrameShapeChanged(Environment* ev)
  211. {
  212.     // Must call inherited so our "view" superclass gets adjusted.
  213.     FW_CFrame::FrameShapeChanged (ev);
  214.     
  215.     CEmbedProxy* proxy = fPart->GetProxy(ev);
  216.     if (proxy != NULL)
  217.     {
  218.         ODFrame* embeddedFrame = proxy->GetEmbeddedFrame(ev, this);
  219.         
  220.         FW_CAcquiredODShape frameShape = MakeFrameShape(ev);
  221.         embeddedFrame->ChangeFrameShape(ev, frameShape, NULL);
  222.     }
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. //    CEmbedFrame::NewEditCommand
  227. //----------------------------------------------------------------------------------------
  228.  
  229. FW_CEditCommand* CEmbedFrame::NewEditCommand(Environment* ev, ODCommandID commandID)
  230. {
  231.     FW_Boolean undoAble = TRUE;
  232.     if (commandID == kODCommandPasteAs)
  233.         undoAble = FALSE;
  234.  
  235.     return FW_NEW(CEmbedEditCommand, (ev, commandID,
  236.                                       (CEmbedPart*)this->GetPart(ev),
  237.                                       this,
  238.                                       GetPresentation(ev)->GetSelection(ev),
  239.                                       undoAble));
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. //    CEmbedFrame::NewDropCommand
  244. //----------------------------------------------------------------------------------------
  245.  
  246. FW_CDropCommand* CEmbedFrame::NewDropCommand(Environment* ev,
  247.                                              FW_CFrame* frame,
  248.                                              ODDragItemIterator* dropInfo, 
  249.                                              ODFacet* odFacet, 
  250.                                              const FW_CPoint& dropPoint)
  251. {
  252.     return FW_NEW(CProxyDropCommand, (ev, (CEmbedPart*)this->GetPart(ev), this,
  253.                                       dropInfo, odFacet, dropPoint));
  254. }
  255.